{extend name='common/_container'} {block name="content"}
<style type="text/css">
	.layui-table tbody tr:hover{
     	background-color: transparent;
	}
	#qks .title{
		font-weight: bold;
	}
</style>
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div style="text-align: center;">
							<span style="font-weight: bold;font-size:30px;">编号：{$customer.id}</span>
							<input type="hidden" name="id" value="{$customer.id}">
						</div>
						<div style="text-align: right;">日期 {:date('Y-m-d')}</div>
						<div id="qks">
							<table class="layui-table">
								<tr>
									<td colspan="2" class="title">建档日期</td>
									<td colspan="2">{$customer.create_time|date='Y-m-d'}</td>
								</tr>
								<tr>
									<td colspan="4">
										<img src="{$customer.idcardimg_one}" style="width: 800px"/>
									</td>
								</tr>
								<tr>
									<td colspan="2" class="title">业务</td>
									<td colspan="2">{$customer.director_name}</td>
								</tr>
								<tr>
									<td colspan="2" class="title">客户电话</td>
									<td colspan="2">{$customer.mobile}</td>
								</tr>
								<tr>
									<td colspan="2" class="title">介绍人</td>
									<td colspan="2">{$customer.introducer_name}</td>
								</tr>
								<tr>
									<td colspan="2" class="title">介绍人电话</td>
									<td colspan="2"><input type="text" name="introducer_mobile" style="width: 100%;border:0;" value="{$customer.introducer_mobile}"></td>
								</tr>
								<tr>
									<td colspan="2" class="title">在台</td>
									<td colspan="2">
										<input type="text" name="work_year" value="{$customer.work_year}" style="width:30px;border:0;">年&nbsp;&nbsp;<input type="text" name="work_month" value="{$customer.work_month}" style="width:30px;border:0;">個月&nbsp;&nbsp;<input type="text" name="work_times" value="{$customer.qkd_info.work_times}" style="width:30px;border:0;">次數</td>
								</tr>
								<tr>
									<td colspan="2" class="title">是否更名</td>
									<td colspan="2">
										<input type="radio" name="is_rename" value="1" {if $customer.is_rename==1}checked="checked"{/if}>是
										<input type="radio" name="is_rename" value="2" {if $customer.is_rename==2}checked="checked"{/if}>否
									</td>
								</tr>
								<tr>
									<td colspan="2" class="title">代保管项</td>
									<td colspan="2">
										<input type="checkbox" name="dbgx" value="1" {if in_array(1,$customer.dbgx)}checked="checked"{/if}>银行本
										<input type="checkbox" name="dbgx" value="2" {if in_array(2,$customer.dbgx)}checked="checked"{/if}>护照
										<input type="checkbox" name="dbgx" value="3" {if in_array(3,$customer.dbgx)}checked="checked"{/if}>居留证
									</td>
								</tr>
								<tr>
									<td colspan="2" class="title">通知书受理编号</td>
									<td colspan="2"><input type="text" name="acceptance_no" value="{$customer.qkd_info.acceptance_no}" style="width: 100%;border:0;"></td>
								</tr>
								<tr>
									<td colspan="2" class="title">工作记录</td>
									<td colspan="2">
										<span>
											中间偷跑
											<input type="checkbox" name="zjtp" value="1" {if $customer.qkd_info.zjtp==1}checked="checked"{/if}>
										</span>
										<span>
											发薪正常
											<input type="checkbox" name="fxzc" value="1" {if $customer.qkd_info.fxzc==1}checked="checked"{/if}>
										</span>
										<span>
											同公司上班
											<input type="checkbox" name="tgssb" value="1" {if $customer.qkd_info.tgssb==1}checked="checked"{/if}>
										</span>
									</td>
								</tr>
								<tr>
									<td class="title">何年在台</td>
									<td class="title">公司名</td>
									<td class="title">工作地点</td>
									<td class="title">
										工作内容
										<span style="position: absolute;right:0" class="add_row"><i class="fa fa-plus"></i></span>
									</td>
								</tr>

								{if empty($customer.qkd_info.history) }
								<tr class="history">
									<td><input type="text" name="hnzt" style="width: 100%;border:0;" value=""></td>
									<td><input type="text" name="company" style="width: 100%;border:0;" value=""></td>
									<td><input type="text" name="work_addr" style="width: 100%;border:0;" value=""></td>
									<td>
										<input type="text" name="work_content" style="width: 100%;border:0;" value="">
										<!-- <span style="position: absolute;right:0" class="delete_row"><i class="fa fa-minus"></i></span> -->
									</td>
								</tr>
								{/if}
								{volist name='customer.qkd_info.history' id='item'}
									<tr class="history">
										<td><input type="text" name="hnzt" style="width: 100%;border:0;" value="{$item.hnzt}"></td>
										<td><input type="text" name="company" style="width: 100%;border:0;" value="{$item.company}"></td>
										<td><input type="text" name="work_addr" style="width: 100%;border:0;" value="{$item.work_addr}"></td>
										<td>
											<input type="text" name="work_content" style="width: 100%;border:0;" value="{$item.work_content}">
											<span style="position: absolute;right:0" class="delete_row"><i class="fa fa-minus"></i></span>
										</td>
									</tr>
								{/volist}
								<tr id="last_row">
									<td colspan="2" class="title">其他</td>
									<td colspan="2"><input type="text" name="others" style="width: 100%;border:0;" value="{$customer.qkd_info.others}"></td>
								</tr>
							</table>
						</div>
						<div style="text-align: center;">
							<button type="button" id="status" class="btn btn-primary button-margin" onclick="CodeGoods.save()">
								<i class="fa fa-check"></i>&nbsp;保存
							</button>&nbsp;&nbsp;&nbsp;&nbsp;
							<button type="button" id="export" class="btn btn-danger button-margin" onclick="CodeGoods.cancel()">
								<i class="fa fa-close"></i>&nbsp;取消
							</button>
							<button type="button" class="btn btn-danger"  id="exportWord">
								<i class="fa fa-eraser"></i>&nbsp;导出word
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var layer_index;
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
			{title: '身份证', field: 'id_card', visible: true, align: 'center', valign: 'middle'},
			// {title: '身份证图', field: 'idcardimg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.idCardFormatter},
 			{title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle'},
			{title: '电话', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
 			{title: '更名', field: 'is_rename', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			{title: '银行本代管', field: 'is_yhb_dg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			{title: '护照代管', field: 'is_hz_dg', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
 			{title: '介绍人', field: 'introducer', visible: true, align: 'center', valign: 'middle'},
 			{title: '承办人', field: 'director', visible: true, align: 'center', valign: 'middle'},
 			{title: '承办人电话', field: '', visible: true, align: 'center', valign: 'middle'},
 			{title: '工作年月', field: 'work_year_month', visible: true, align: 'center', valign: 'middle'},
 			{title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',formatter: 'CodeGoods.buttonFormatter'},
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(value){
			var str= '';
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+value+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+value+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;'
			str += '<button type="button" class="btn btn-info btn-xs" title="请款单"  onclick="CodeGoods.qingkuan('+value+')"><i class="fa fa-eye"></i>&nbsp;请款单</button>&nbsp;'
			/*str += '<button type="button" class="btn btn-danger btn-xs" title="查看"  onclick="CodeGoods.view('+value+')"><i class="fa fa-trash"></i>&nbsp;查看</button>&nbsp;'*/
			return str;
		}
	}

	CodeGoods.isNotFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">是</span>';
				break;
				case '2':
					return '<span class="label label-warning">否</span>';
				break;
			}
		}
	}

	CodeGoods.idCardFormatter = function(value,row,index) {
		var reg = RegExp(/|/);
		if(value.match(reg)){
			strs = value.split("|");
		}
		var img = '';
		//console.log(strs)
		for (i=0;i<strs.length ;i++ )
		{
			img = img + "<a href=\"javascript:void(0)\" onclick=\"previewImg('"+strs[i]+"')\"><img height='50' src="+strs[i]+"></a>";
		}
		if(img){
			return img;
		}
	}

	CodeGoods.amountFormatter = function(value,row,index) {
		if(value){
			return '<span class="label label-info">'+value+'</span>';
		}
	}

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',0)" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'"  type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',1)">';
			}
		}
	}

	CodeGoods.create_timeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value);
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['id_card'] = $("#id_card").val();
		queryData['first_name'] = $("#first_name").val();
		queryData['birth_year'] = $("#birth_year").val();
		queryData['last_name'] = $("#last_name").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.status = function (value) {
		if (this.check()) {
			var idx = '';
			$.each(CodeGoods.seItem, function() {
				idx += ',' + this.id;
			});
			idx = idx.substr(1);
			if(idx.indexOf(",") !== -1){
				Feng.info("请选择单条数据！");
				return false;
			}
			var index = layer.open({type: 2,title: '转为劳保局入款',area: ['600px', '400px'],fix: false, maxmin: true,content: Feng.ctxPath + '/stepfive/status?id='+idx});
			this.layerIndex = index;
		}
	}


	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['100', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+idx});
				this.layerIndex = index;
			}
		}
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('ids', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg);
						}
					});
					ajax.set('ids', idx);
					ajax.start();
				});
			}
		}
	}


	CodeGoods.qingkuan = function (value) {
		layer_index = layer.open({type: 2,title: '请款单',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/income/qingKuan?id='+value});
	}

	CodeGoods.save = function (value) {
		var data={};
		data.introducer_mobile=$("input[name=introducer_mobile]").val();
		data.work_year=$("input[name=work_year]").val();
		data.work_month=$("input[name=work_month]").val();
		data.work_times=$("input[name=work_times]").val();
		data.is_rename=$("input[name=is_rename]:checked").val();
		if(typeof(data.is_rename) =='undefined'){
			data.is_rename='';
		}
		var dbgx=[];
		$('input[name=dbgx]:checked').each(function(){
			dbgx.push($(this).val());
		});
		data.dbgx=dbgx;
		data.acceptance_no=$("input[name=acceptance_no]").val();
		data.zjtp=$("input[name=zjtp]:checked").val();
		if(typeof(data.zjtp) =='undefined'){
			data.zjtp='';
		}
		data.fxzc=$("input[name=fxzc]:checked").val();
		if(typeof(data.fxzc) =='undefined'){
			data.fxzc='';
		}
		data.tgssb=$("input[name=tgssb]:checked").val();
		if(typeof(data.tgssb) =='undefined'){
			data.tgssb='';
		}
		var history=[];
		$(".history").each(function(){
			var item={};
			item.hnzt=$(this).find("input[name=hnzt]").val();
			item.company=$(this).find("input[name=company]").val();
			item.work_addr=$(this).find("input[name=work_addr]").val();
			item.work_content=$(this).find("input[name=work_content]").val();
			history.push(item);
		});
		data.history=history;
		data.others=$("input[name=others]").val();
		console.log(data);
		var id=$("input[name=id]").val();
		$.ajax({
			type: "POST",
			url: "{:url('admin/Income/qingKuan')}",
			dataType: "json",
			data: {id:id,content:JSON.stringify(data)},
			success: function (result) {
				if (result.status == 0) {
					// parent.layer.msg ("保存成功");
					layer.alert('保存成功',function(){
						CodeGoods.cancel();
					});
					//CodeGoods.cancel();
				} else {
					parent.layer.msg ("保存失败");
				}

			},
			error: function (result) {
				parent.layer.msg ("请求失败");
			}
		});

	}

	CodeGoods.cancel = function (value) {
		var index = parent.layer.getFrameIndex(window.name);
		setTimeout(parent.layer.close(index),1000);
	}

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};
	$("#exportWord").bind("click", function() {
		exportWord()
		//do something;
	});
	function exportWord() {
		var id=$("input[name=id]").val();
		Feng.confirm("是否导出？", function () {
			var ajax = new $ax(Feng.ctxPath + "/Income/export?"+"&id=" +id, function (data) {
				if ('00' === data.status) {
					//Feng.success(data.msg);
					console.log("/download/data/" + data.data.file_nm);
					window.location = "/public/download/data/" + data.data.file_nm;
					//CodeGoods.table.refresh();
				} else {
					Feng.error(data.msg);
				}
			});
			ajax.start();
		});
	}
	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/income/index"+url,defaultColunms,500);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();

		$(".add_row").click(function(){
			var html='<tr class="history"><td><input type="text" name="hnzt" style="width: 100%;border:0;"></td><td><input type="text" name="company" style="width: 100%;border:0;"></td><td><input type="text" name="work_addr" style="width: 100%;border:0;"></td><td><input type="text" name="work_content" style="width: 100%;border:0;"><span style="position: absolute;right:0" class="delete_row"><i class="fa fa-minus"></i></span></td></tr>';
			$(html).insertBefore("#last_row");
		})
		$(document).on('click','.delete_row',function(){
			$(this).parent().parent().remove();
		})

		$('input[name=is_rename]').bind('click', function () {
			$('input[name=is_rename]').not(this).attr("checked", false);
		});
	});
</script>
{/block}
